<?php

if (!defined('TS_ROOT')) die(basename(__FILE__));
if (defined('PAGE_HEADER_SENT')) return;

global $page_cfg, $userdata, $user, $ts_cfg, $template, $lang, $images;

$logged_in = (int) !empty($userdata['session_logged_in']);

// Generate logged in/logged out status
if ($logged_in)
{
	$u_login_logout = TS_ROOT . LOGIN_URL . "?logout=1";
}
else
{
	$u_login_logout = TS_ROOT . LOGIN_URL;
}


$template->assign_vars(array(
	'SITENAME'			 => $ts_cfg['sitename'],
	'PAGE_TITLE'		 => $lang['T_INDEX'],
	
	'U_INDEX'            => TS_ROOT ."index.php",
	
	'SIMPLE_HEADER'      => !empty($gen_simple_header),
	'CONTENT_ENCODING'   => $ts_cfg['lang'][$userdata['user_lang']]['encoding'],
	
	'USER_OPTIONS_JS'    => (IS_GUEST) ? '{}' : ts_json_encode($user->opt_js),
	'INCLUDE_BBCODE_JS'  => !empty($page_cfg['include_bbcode_js']),
	
	'USE_TABLESORTER'    => !empty($page_cfg['use_tablesorter']),
	
	'IN_ADMIN'           => defined('IN_ADMIN'),
	'USER_LANG'          => $userdata['user_lang'],
	
	'IS_GUEST'           => IS_GUEST,
	'IS_USER'            => IS_USER,
	'IS_ADMIN'           => IS_ADMIN,
	'IS_MOD'             => IS_MOD,
	'IS_AM'              => IS_AM,
	
	'U_LOGIN_LOGOUT'     => $u_login_logout,
	'U_REGISTER'         => "user.php?mode=register",
	'U_TERMS'            => $ts_cfg['terms_and_conditions_url'],
	'U_OPTIONS'          => "user.php?mode=edit",
	'U_SEND_PASSWORD'    => "user.php?mode=sendpassword",
	'U_PROFILE'          => PROFILE_URL . $userdata['user_id'],
	
	'CURRENT_TIME'       => sprintf($lang['CURRENT_TIME'], bb_date(TIMENOW, $ts_cfg['last_visit_date_format'], false)),
	'S_TIMEZONE'         => preg_replace('/\(.*?\)/', '', sprintf($lang['ALL_TIMES'], $lang['TZ'][str_replace(',', '.', floatval($ts_cfg['board_timezone']))])),
	'BOARD_TIMEZONE'     => $ts_cfg['board_timezone'],
	
	'LOGGED_IN'          => $logged_in,
	'SESSION_USER_ID'    => $userdata['user_id'],
	
    'HTML_AGREEMENT'     => LANG_DIR . 'ads/user_agreement.html',
	'HTML_COPYRIGHT'     => LANG_DIR . 'ads/copyright_holders.html',
	'HTML_ADVERT'        => LANG_DIR . 'ads/advert.html',
	'HTML_SIDEBAR_1'     => LANG_DIR . 'ads/sidebar1.html',
	
	
));

if (!IS_GUEST)
{
	header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
	header('Expires: 0');
	header('Pragma: no-cache');
}

$template->set_filenames(array('page_header' => 'page_header.tmpl'));
$template->pparse('page_header');

define('PAGE_HEADER_SENT', true);

if (!$ts_cfg['gzip_compress'])
{
	flush();
}
